package org.iori.luodan.logic;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.iori.luodan.base.BaseDaoFactory;
import org.iori.luodan.dao.CategoryDao;
import org.iori.luodan.entity.ApnsInfoEntity;
import org.iori.luodan.entity.CategoryInfoEntity;
import org.iori.luodan.entity.UserApnsInfoEntity;

import com.iori.common.constant.ArchConstant;
import com.iori.common.log.FounderLog;
import com.iori.common.log.LogFactory;

/**
 * [クラス名]<br>
 * CategoryLogic.java<br>
 * [機能概要]<br>
 * 検索ロジック<br>
 * <br>
 * [変更履歴]<br>
 * 2012/11/13 ver1.00 新規作成<br>
 * 
 * @author luodan CORPORATION lun_xing
 * @version 1.00
 */
public class CategoryLogic {

    // Log出力クラスを定義
    private static FounderLog log = LogFactory.getFounderLog(CategoryLogic.class);

    // DAO初期化
    private static CategoryDao categoryDao = BaseDaoFactory.getCategoryDao();

    /**
     * コンテンツリストの内容取得
     * <br>
     * @param offset
     * @param limit
     * @param TitleName
     * @return
     * @throws Exception
     */
    public ArrayList getCategoryInfo(int start_row, int row_count) throws Exception {
		ArrayList arrayList = new ArrayList();
		List list = categoryDao.getCategoryInfo(start_row, row_count);
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				HashMap map = (HashMap)list.get(i);
				CategoryInfoEntity entity = this.mapToCategoryInfoEntity(map);
				if (null != entity) {
					arrayList.add(entity);
				}
		    }
		}
		return arrayList;
    }
    
    private CategoryInfoEntity mapToCategoryInfoEntity(HashMap map) {
    	if (null == map) {
    		return null;
    	}
    	Object obj = null;
    	obj = map.get("CAT_ID");
    	int cat_id = 0;
    	if (null != obj) {
    		cat_id = Integer.valueOf(obj.toString().trim());
    	}
    	
    	obj = map.get("CAT_NAME");
    	String cat_name = "";
    	if (null != obj) {
    		cat_name = obj.toString().trim();
    	}
    	
    	obj = map.get("GOODS_THUMB");
    	String goods_thumb = "";
    	if (null != obj) {
    		goods_thumb = obj.toString().trim();
    	}

    	CategoryInfoEntity entity = new CategoryInfoEntity();

    	entity.setCat_id(cat_id);
    	entity.setCat_name(cat_name);
    	entity.setGoods_thumb(goods_thumb);

    	return entity;
    }
}
